# This file is part of The Vu Toolkit.
#
# The Vu Toolkit is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# The Vu Toolkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with The Vu Toolkit; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
#
# Copyright © Zak Fenton 2008
#

require 'set'

module Vu::SVG
	# A group ("g" element). Most GUI elements are likely to be based on this
	# type of element.
	class Group
		# Elements within this group
		attr_reader :children
	
		# Adds a child (it will be ON TOP OF earlier added children)
		def add_child (c)
			@children.add(c)
		end
		
		# Removes a child
		def remove_child (c)
			@children.delete(c)
		end
	
		# Creates a group
		def initialize ()
			@children = Set.new()
			@transform = Transformation.new
			super()
		end
		
		# Renders the children on given Cairo context
		def render_children_to_cairo(cr)
			for c in children
				c.render_to_cairo(cr)
			end
		end
		
		def render_to_cairo (cr)
			cr.save()
			
			transform.apply_to_cairo(cr)
			render_children_to_cairo(cr)
			
			cr.restore()
		end
		
		# The transformation. Equivalent to the "transform" SVG tag. Returns an
		# object on which you can the .rotate!,.translate!,.scale!, etc. It is
		# for now a Cairo::Matrix, but a special purpose type may be added.
		def transform
			@transform
		end
	end
end

